﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Shakes_and_Fidget___Charplaner.Classes
{
	public class Unit
	{
		public Enums.Class class_;
		public int end_str { get; set; }
		public int end_dex { get; set; }
		public int end_int { get; set; }
		public int end_stam { get; set; }
		public int end_luck { get; set; }
		public int base_str { get; set; }
		public int base_dex { get; set; }
		public int base_int { get; set; }
		public int base_stam { get; set; }
		public int base_luck { get; set; }
		public int level { get; set; }
		public int armor { get; set; }
		public int avoidchance { get; set; }
		public int[] weapondamage = new int[2];
		public bool lifebonus { get; set; }

		public Unit(Enums.Class class_, int base_str, int base_dex, int base_int, int base_stam, int base_luck, int level, int armor, int avoidchance = 0, int weapondamage_min = 0, int weapondamage_max = 0, int life = 0)
		{
			this.class_ = class_;
			this.base_str = base_str;
			this.base_dex = base_dex;
			this.base_int = base_int;
			this.base_stam = base_stam;
			this.base_luck = base_luck;
			this.level = level;
			this.armor = armor;
			this.avoidchance = avoidchance;
			this.end_str = GetSTR();
			this.end_dex = GetDEX();
			this.end_int = GetINT();
			this.end_stam = GetSTAM();
			this.end_luck = GetLUCK();
		}
		public Unit()
		{ }
		public virtual int GetSTR()
		{
			end_str = base_str;
			return end_str; 
		}
		public virtual int GetDEX()
		{
			end_dex = base_dex;
			return end_dex;
		}
		public virtual int GetINT()
		{
			end_int = base_int;
			return end_int;
		}
		public virtual int GetSTAM()
		{
			end_stam = base_stam;
			return end_stam;
		}
		public virtual int GetLUCK()
		{
			end_luck = base_luck;
			return end_luck;
		}
		public int GetLifeMult()
		{
			switch (this.class_)
			{
				case Enums.Class.WARRIOR:
					return 5;
				case Enums.Class.MAGE:
					return 2;
				case Enums.Class.ARCHER:
					return 4;
				default:
					return 0;
			}
		}
		public int GetMainAttribute()
		{
			switch (this.class_)
			{
				case Enums.Class.WARRIOR:
					return GetSTR();
				case Enums.Class.MAGE:
					return GetINT();
				case Enums.Class.ARCHER:
					return GetDEX();
				default:
					return 0;
			}
		}
		public int GetMainAttributeID()
		{
			switch (this.class_)
			{
				case Enums.Class.WARRIOR:
					return (int)Enums.Stat.STRENGTH;
				case Enums.Class.MAGE:
					return (int)Enums.Stat.INTELLIGENCE;
				case Enums.Class.ARCHER:
					return (int)Enums.Stat.DEXTERITY;
				default:
					return 0;
			}
		}
		public int[] GetWeaponDamage()
		{
			if (this.weapondamage != null)
				return new int[] { weapondamage[0], weapondamage[1] };
			return new int[] { 0, 0 };
		}
		public double GetLife()
		{
			return GetSTAM() * GetLifeMult() * (this.level + 1);
		}
		public double GetCrit()
		{
			return GetLUCK() * 5 / (this.level * 2);
		}
		public double[] GetAttackPower(int def = 0)
		{
			return new double[] { GetWeaponDamage()[0] * (1 + (GetMainAttribute() - def) / 10), GetWeaponDamage()[1] * (1 + (GetMainAttribute() - def) / 10) };
		}
		public int GetResistance()
		{
			return GetINT() / 2;
		}
		public int GetDefence()
		{
			return GetSTR() / 2;
		}
		public int GetDodge()
		{
			return GetDEX() / 2;
		}
		public double GetDamageReduction()
		{
			double dmgred = 0;
			switch (class_)
			{
				case Enums.Class.ARCHER:
					dmgred = (this.armor / this.level);
					if (dmgred > 25)
						dmgred = 25;
					break;
				case Enums.Class.WARRIOR:
					dmgred = (this.armor / this.level);
					if (dmgred > 50)
						dmgred = 50;
					break;
				case Enums.Class.MAGE:
					dmgred = (this.armor / this.level);
					if (dmgred > 10)
						dmgred = 10;
					break;

			}
			return dmgred;
		}
		//<summary>
		//Schaden = (Schadensbereich - Rüstung vom Gegner) * (1.5^(Rundenanzahl - 1))
		//Es wird die Def des Gegners von dem eigenen HA abgezogen und dann der Schaden berechnet.
		//Aus diesem Schaden wird ein zufälliger Wert gewählt
		//Dem wird die prozentuale Schadensveringerung abgezogen
		//Dann wird der "Aggro"-Multiplikator hinzugefügt.
		//</summary>
		public double GetDamage(int round, int def, double dmgred)
		{
			double[] ap = { GetAttackPower(def)[0], GetAttackPower(def)[1] };
			Random dmg = new Random();
			double damage = dmg.Next((int)ap[0], (int)ap[1]);
			damage *= 1 - (dmgred / 100);
			damage *= (Math.Pow(1.5, (round - 1)));
			return damage;
		}

	}

}
